/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reyes.mysite.struts;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import reyes.mysite.dao.GenericDAO;
import reyes.mysite.jdo.Blog;
/**
 *
 * @author reyesyang
 */
public class PostCommentActionForm extends org.apache.struts.action.ActionForm {

    private String blogKey;
    private String role;
    private String poster;
    private String email;
    private String website;
    private String content;

    public void setBlogKey(String blogKey) {
        this.blogKey = blogKey;
    }

    public String getBlogKey() {
        return this.blogKey;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getRole() {
        return this.role;
    }
    
    public void setPoster(String poster) {
        this.poster = poster;
    }

    public String getPoster() {
        return this.poster;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail() {
        return this.email;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    public String getWebsite() {
        return this.website;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getContent() {
        return this.content;
    }

    public PostCommentActionForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        GenericDAO<Blog> blogDAO = new GenericDAO<Blog>();
        Blog blog = blogDAO.getById(Blog.class, Long.valueOf(blogKey));
        request.setAttribute("blog", blog);
        
        ActionErrors errors = new ActionErrors();
        if (poster == null || poster.length() < 1) {
            errors.add("poster", new ActionMessage("errors.nullOrEmpty"));
        } else if(email == null || email.length() < 1) {
            errors.add("email", new ActionMessage("errors.nullOrEmpty"));
        } else if(content == null || content.length() < 1) {
            errors.add("content", new ActionMessage("errors.nullOrEmpty"));
        }
        return errors;
    }
}
